package net.wanho.controller;

import net.wanho.entity.User;
import net.wanho.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
@RefreshScope // nacos配置自动刷新
public class UserController {

    @Value("${server.port}")
    int port ;

    @Value("${spring.datasource.url}")
    private String url;

    @Value("${shop.share.name}")
    private String name;

    @RequestMapping("/test")
    public String test(){
        return "provider:"+port;
    }

    @GetMapping
    public AjaxResult list(String username){
        return AjaxResult.success(new User(1001, username, "123"));
    }

    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable int id){
        return AjaxResult.success(id);
    }

    @PostMapping
    public AjaxResult add(@RequestBody User user){
        return AjaxResult.success(user);
    }

    @GetMapping("/info")
    public String info(){
        return url + "----------------->" + name;
    }
}